//导入express模块
const express = require('express');

//创建应用对象
const app = express();

app.use((req, res, next) => {
    //获取referer
    let referer = req.get('referer');
    if (referer) {
        //url实例化
        let url = new URL(referer);
        //获取hostname
        let hostname = url.hostname;
        //判断hostname是否等于127.0.0.1
        if (hostname != '127.0.0.1') {
            //响应404
            res.status(404).send('<h1>404 Not Foune</h1');
        }
        next();
    }
});

app.use(express.static(__dirname + '/public'));

//监听端口，启动服务
app.listen(3000, () => {
    console.log('服务已经启动，3000端口正在监听中……');
})